//=============================================================================
// Outpost.
//=============================================================================

class TFOutpost extends TFStation
	placeable;

var int outpdist;

replication
{
    reliable if( Role==ROLE_Authority )
	outpdist;
}

function Upgrade(pawn p)
{
    super.Upgrade(p);

    if(grade==3) tfgri(level.Game.GameReplicationInfo).baseshield[myteam]++;
}

state Ready
{
    function BeginState()
    {
        super.BeginState();

        //CONTROL
	    if(tfgame(level.game)!=none && tfgri(level.game.gamereplicationinfo)!=none)
	        tfgri(level.game.gamereplicationinfo).maxcontrol[myteam]+=tfgame(level.game).BuildLimit/2;

        if(myteam==0) setstaticmesh(StaticMesh'TFMedia.Buildings.tfOutpostRed');
        else setstaticmesh(StaticMesh'TFMedia.Buildings.tfOutpostBlu');

        outpdist=float(tfgame(level.Game).outpostdist)*(float(tfgame(level.Game).outpostarea)/100);

        settimer(0.1,true);
    }

    function Timer()
    {
        local tfStation s;

        foreach CollidingActors(class'tfStation',s,outpdist*48,location)
        {
            if(s.myteam==myteam && s!=self) s.nearOutpost=grade;
        }
    }
}

function Destructed(pawn killer, bool recycled)
{
    local tfStation s;

    if(grade==3) tfgri(level.Game.GameReplicationInfo).baseshield[myteam]--;

    if(grade>0)
    {
        //CONTROL
	    if(tfgame(level.game)!=none && tfgri(level.game.gamereplicationinfo)!=none)
	        tfgri(level.game.gamereplicationinfo).maxcontrol[myteam]-=tfgame(level.game).BuildLimit/2;
    }

    foreach CollidingActors(class'tfStation',s,float(tfgame(level.Game).outpostdist)*24,location)
    {
        if(s.myteam==myteam) s.nearOutpost=0;
    }

    super.Destructed(killer, recycled);
}

defaultproperties
{
     MaxHealth=2000.000000
     BuildTime=90.000000
     chunkcount=15
     BuildingName="Outpost"
     NameIndex=6
     teamflareDS=1.500000
     FXClass=Class'taskforces.TFOutpostFX'
     StaticMesh=StaticMesh'TFMedia.Buildings.tfOutpost'
     AmbientSound=Sound'TFMedia.Buildings.tfOutpostAmb'
     SoundVolume=222
}
